/*=================================================================*/
/*               IS-2000  TOD                                      */
/*=================================================================*/
#ifndef H_RCGD_TODCMD_H
#define H_RCGD_TODCMD_H

typedef struct TOD_S{
    unsigned char	STATUS;
    unsigned char   	ERROR;
    
    unsigned char	S_CODE, E_CODE;
    unsigned char	U_S_CODE, U_E_CODE;
    
    unsigned char	BUFFER[20];
    short			SKIP_TIMER;
    short			SKIP_TOD_TIMER;
} TOD_;



/* STATUS format */
typedef struct STATUS_S{

    short   		ID;			/*  2 */

	time_			TIME;			
	long			ANTDLY;
	char			Valid;		
	char			LEAPSECOND;
	unsigned char	TIMEMODE;		
	char			LOCALHOUR;	
	char			LOCALMINUTE;

	char			PosSurvey;
	short			PosNo;
	short			PosCounter;
    P_  			CURRENT; 	/* 12 */
    P_  			AVERAGE;	/* 12 */
    P_  			LASTHELD;	/* 12 */

	TS_				TRACK;		/* 22 */	

	OP_				OPERATION;	/*  4 */	
	int				RunningTime;
	int				HoldoverCounter;
	char			HoldoverRecovery;
	
	char			ANTENNA;
    Diag_   		DIAG;		/* 10 */	
	
    
    int   			DAC;        /*  4 */	/* Float -> Int*/
    int     		TimeOffset;      /*  4 */
    int     		AvgTimeOffset; /*  4 */   
    short   		T_OCXO;		/*  2 */
    short 			T_EXT;		/*  2 */

    short			Index;

    short   TAIL;       /*  2 */                                                          
} STATUS_;    /*  122 */




/* Command.SERVICE */
#define CMD_PRE_INPUT	0
#define	CMD_INPUT		1
#define	CMD_PARSING		2
#define	CMD_EXECUTION 	3
#define	CMD_REPLY 		4


typedef struct CMD_S{
	char	CommandSet;
	char	CallCount;
	char	Port;
	short	ID;
	char	Parameter[64];
} CMD_; 


#define MAX_COMMAND_CASCADE	6
typedef struct Command_S{
	char	SERVICE;
	char	COMMAND_SET;
	char	Count;
	char	Current;
	char 	Input[256];
	char	Output[256];
	CMD_	Queue[MAX_COMMAND_CASCADE];
}Command_;


typedef struct Common_Command_S{
	Command_ TOD_PORT;
	Command_ CTRL_PORT;
} COMMAND_;





#define	EXE_END			0
#define	EXE_ERROR		1
#define	EXE_ING			2



#define ASCII	0
#define BINARY	1



#define NOW			100
#define TOD_CALC_START		 9



extern COMMAND_	COMMAND;

extern void Init_COMMAND(void);
extern void ExecuteCommand(char);
extern void ReplyCommand(char);
extern void STATUS_OUT(int,char);
extern void TOD_OUT(int,char);
extern void TOD_OUT_FPGA(void);

#endif
